package com.example.fragment.tool;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.fragment.R;


public class LoginPeople extends Dialog implements View.OnClickListener{
    private ImageView mIvFace;
    private ImageView mIvswitch;
    private ImageView mIvLogout;
    private IOnSwitchListener onSwitchListener;
    private IOnLogOutListener onLogOutListener;
    private TextView mTvUser,mTvNumber;
    private String username,usernumber;
    public LoginPeople(@NonNull Context context) {
        super(context);
    }
    public LoginPeople(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }
    protected LoginPeople(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_loginpeople);
        mIvFace =findViewById(R.id.iv_face1);
        mIvswitch=findViewById(R.id.iv_switch);
        mIvLogout =findViewById(R.id.iv_lognout);
        mTvUser =findViewById(R.id.tv_user);
        mTvNumber =findViewById(R.id.tv_number);

       mIvswitch.setOnClickListener(this);
       mIvLogout.setOnClickListener(this);
        if(!TextUtils.isEmpty(username)){
            mTvUser.setText(username);
        }
        if(!TextUtils.isEmpty(usernumber)){
            mTvNumber.setText(usernumber);
        }
        //设置屏幕宽度
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = getWindow().getAttributes();
        Point size = new Point();
        d.getSize(size);
        p.width = (int) (size.x*0.27);//设置dialog的宽度为手机屏幕宽度的0，5
        p.height=(int) (size.x*0.35);
        getWindow().setAttributes(p);
    }
    public LoginPeople setmIvswitch(IOnSwitchListener listener){
        this.onSwitchListener=listener;
        return this;
    }
    public LoginPeople setmIvLogout(IOnLogOutListener listener){
        this.onLogOutListener=listener;
        return this;
    }
    public ImageView getmIvFace() {
        return mIvFace;
    }

    public void setmIvFace(ImageView mIvFace) {
        this.mIvFace = mIvFace;
    }

    public TextView getmTvUser() {
        return mTvUser;
    }

    public LoginPeople setmTvUser(String username) {
        this.username = username;
        return this;
    }

    public TextView getmTvNumber() {
        return mTvNumber;
    }

    public LoginPeople setmTvNumber(String usernumber) {
        this.usernumber = usernumber;
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_switch:
                if(onSwitchListener!= null){
                    onSwitchListener.onSwitch(this);
                }
                dismiss();
                break;
            case R.id.iv_lognout:
                if(onLogOutListener!= null){
                    onLogOutListener.onLogOut(this);
                }
                dismiss();
                break;
        }
    }


    public interface IOnSwitchListener{
        void onSwitch(LoginPeople loginPeople);
}
    public interface IOnLogOutListener{
        void onLogOut(LoginPeople loginPeople);
    }
}
